import { IVerificationAdapter } from "../index";

export class DataVerify {
    static Current: DataVerify = new DataVerify();
    constructor() { }
    private adapterList: { adpaterName: string; adapter: IVerificationAdapter }[] = [];

    AddAdapter(name: string, adapter: IVerificationAdapter) {
        this.adapterList.push({ adpaterName: name, adapter: adapter });
    }

    Verify(ctx: any) {
        for (let item of this.adapterList) {
            if (ctx.originalUrl.indexOf(item.adpaterName) > -1) {
               let requestBody = item.adapter.Verify(ctx.request.body);
               ctx.request.body = requestBody;
               break;
            }
        }

        return ctx;
    }
}